package greed;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Classname : QueueReconstructionByHeight
 * @Description : 406. 根据身高重建队列
 * https://leetcode.cn/problems/queue-reconstruction-by-height/
 * @Author : chentianyu
 * @Date 2023/2/24 00:10
 */


public class QueueReconstructionByHeight {
    public int[][] reconstructQueue(int[][] people) {
        Arrays.sort(people, (o1, o2)->{
            if (o1[0] == o2[0]) return Integer.compare(o1[1], o2[1]);
            else return Integer.compare(o2[0], o1[0]);
        });
        List<int[]> ans = new ArrayList<>();
        for (int[] peo : people) {
            ans.add(peo[1], peo);
        }
        return ans.toArray(new int[people.length][2]);
    }
}
